export default {
  //获取参数名获得地址栏参数值
  getQueryString(name) {
    if (process.client) {//判断为客户端
      let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      let r = window.location.search.substr(1).match(reg);
      // console.log(r)
      if (r != null) return decodeURI(r[2]);
    }
    return null;
  },

  getRESTQueryString(index) {
    if (process.client) {//判断为客户端
      let pathname = window.location.pathname;
      //--------"/player/18/17/0d897d1e939d43f6bb016b3140358040"
      let r = pathname.split('/');
      //r[3]=17
      console.log(r[index])
    }
    return null;
  },
  getPathName(){
    if (process.client) {//判断为客户端
      return  window.location.pathname;

    }
    return null;
  },
  //根据秒数获取时长
  formatSeconds(value) {
    let secondTime = parseInt(value);// 秒
    let minuteTime = 0;// 分
    let hourTime = 0;// 小时
    if (secondTime > 60) {//如果秒数大于60，将秒数转换成整数
      //获取分钟，除以60取整数，得到整数分钟
      minuteTime = parseInt(secondTime / 60);
      //获取秒数，秒数取佘，得到整数秒数
      secondTime = parseInt(secondTime % 60);
      //如果分钟大于60，将分钟转换成小时
      if (minuteTime > 60) {
        //获取小时，获取分钟除以60，得到整数小时
        hourTime = parseInt(minuteTime / 60);
        //获取小时后取佘的分，获取分钟除以60取佘的分
        minuteTime = parseInt(minuteTime % 60);
      }
    }
    let result;
    if (secondTime < 10) {
      secondTime = "0" + secondTime;
    }
    result = secondTime;

    if (minuteTime < 10) {
      minuteTime = "0" + minuteTime
    } else if (minuteTime < 0) {
      minuteTime = "00";
    }
    result = minuteTime + ":" + result

    if (hourTime < 10 && hourTime > 0) {
      hourTime = "0" + hourTime
      result = hourTime + ":" + result
    }
    return result;
  },

  changeTime(time) {
    let dateTimeStamp = new Date(time).getTime()


    let minute = 1000 * 60;
    let hour = minute * 60;
    let day = hour * 24;

    let month = day * 30;
    let year = month * 12;
    let now = new Date().getTime();
    let diffValue = now - dateTimeStamp;
    let result = ""
    if (diffValue < 0) {
      return;
    }

    let monthC = diffValue / month;
    let weekC = diffValue / (7 * day);
    let dayC = diffValue / day;
    let hourC = diffValue / hour;
    let minC = diffValue / minute;
    let yearC = diffValue / year
    if (yearC >= 1) {
      return "" + parseInt(yearC) + "年前";
    }
    if (monthC >= 1) {
      result = "" + parseInt(monthC) + "月前";
      //result =time
    } else if (weekC >= 1) {
      result = "" + parseInt(weekC) + "周前";
    } else if (dayC >= 1) {
      result = "" + parseInt(dayC) + "天前";
    } else if (hourC >= 1) {
      result = "" + parseInt(hourC) + "小时前";
    } else if (minC >= 1) {
      result = "" + parseInt(minC) + "分钟前";
    } else {
      result = "刚刚";
    }

    return result;
  }

}
